<?php
/**
 * The coltroller to manage the header for the application
 * 
 * @author Youssef Driouach
 *
 * 20 août 2012
 */

class HeaderController extends Zend_Controller_Action
{

	public function init()
	{
		
		 
	}

	/**
	 * The action to manage the menu type.
	 */
	public function indexAction()
	{
		
		$this->view->statusConn = false;
		$helperUrl = new Zend_View_Helper_Url ( );
		$this->view->homeUrl = $helperUrl->url ( array ('controller' => 'index' ) , 'default', true);
		$auth = Zend_Auth::getInstance ();
		if ($auth->hasIdentity ()) {
			$userMapper = new Application_Model_UserMapper();
			$user = $userMapper->find($auth->getIdentity ()->id_user);
			//$username = strtoupper ( substr ( $auth->getIdentity ()->lastName, 0, 1 ) ) . ' ' . $auth->getIdentity ()->firstName . '.';
			$logoutLink = $helperUrl->url ( array ('action' => 'logout', 'controller' => 'login' ) , 'default', true);
			$myobjectsLink = $helperUrl->url ( array ('controller' => 'myobjects' ) , 'default', true);
			$profilLink = $helperUrl->url ( array ('id_user' => $user->getUserId() ) , 'profilRoute', true);
			
			
			$this->view->user = $user;
			$this->view->statusConn = true;
			$this->view->bienvenue = 'Bienvenue';
			$this->view->logoutLink = $logoutLink;
			$this->view->myobjectsLink =  $myobjectsLink;
			$this->view->profilLink = $profilLink;
		}
		else{
			$this->view->signInLink = $signInLink = $helperUrl->url ( array ('controller' => 'login' ) , 'default', true);
			$this->view->registerLink = $RegisterLink = $helperUrl->url ( array ('controller' => 'registration' ) , 'default', true);
		}
		 
	}


}
